package cn.stylefeng.guns.modular.productfunction.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.productfunction.entity.ShiProductFunction;
import cn.stylefeng.guns.modular.productfunction.mapper.ShiProductFunctionMapper;
import cn.stylefeng.guns.modular.productfunction.model.params.ShiProductFunctionParam;
import cn.stylefeng.guns.modular.productfunction.model.result.ShiProductFunctionResult;
import cn.stylefeng.guns.modular.productfunction.service.ShiProductFunctionService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *    产品功能表
 * @author 石博士
 * @since 2019-07-05
 */
@Service
public class ShiProductFunctionServiceImpl extends ServiceImpl<ShiProductFunctionMapper, ShiProductFunction> implements ShiProductFunctionService {


    @Autowired
    private ShiProductFunctionMapper shiProductFunctionMapper;



    @Override
    public void add(ShiProductFunctionParam param){
        ShiProductFunction entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ShiProductFunctionParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ShiProductFunctionParam param){
        ShiProductFunction oldEntity = getOldEntity(param);
        ShiProductFunction newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ShiProductFunctionResult findBySpec(ShiProductFunctionParam param){
        return null;
    }

    @Override
    public List<ShiProductFunctionResult> findListBySpec(ShiProductFunctionParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(ShiProductFunctionParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ShiProductFunctionParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ShiProductFunction getOldEntity(ShiProductFunctionParam param) {
        return this.getById(getKey(param));
    }

    private ShiProductFunction getEntity(ShiProductFunctionParam param) {
        ShiProductFunction entity = new ShiProductFunction();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

//    @Override
//    public ShiProductFunctionResult edit(@Param("id") String id){
//        ShiProductFunction entity = this.getById(id);
//        return entity;
//    }



    /**
     * 使用左连接查询所有的功能对比数据
     */
    public List<ShiProductFunctionResult> ProductFunctionList(){
        return shiProductFunctionMapper.ProductFunctionList();
    }


    public ShiProductFunctionResult edit(@Param("id") String id){
        return shiProductFunctionMapper.edit(id);
    }













}
